import { useState } from "react";
export function useCountDown(time = 60, cb) {
    const [count, setCount] = useState(time)
    const [isCurt, setIsCurt] = useState(false)

    const start = () => {
        setIsCurt(true)

        setInterval((prev) => {
            if (prev <= 1) {
                setCount(time)
                cb && cb()
                setIsCurt(false)

            }
            return prev - 1
        }, 1000)

    }
    const reset = () => {
        setCount(time)
        setIsCurt(false)
    }
    return { count, isCurt, start, reset }
}